package com.taotao.job.core.enums;


import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * 任务类型
 *
 * @author fanbeibei
 * @version 1.0
 * @date 2021/2/3 17:05
 */
@Getter
@AllArgsConstructor
public enum JobType {

    /**
     *普通任务
     */
    NOMAL(1, "普通任务"),
    /**
     *
     */
    WORK_FLOW(2, "工作流任务"),
    /**
     *
     */
    WORK_FLOW_NODE(3, "工作流任务节点"),
    /**
     *
     */
    WORK_FLOW_NODE_RECURVE(4, "工作流任务做另一个工作流任务节点");

    private final Integer code;

    private final String text;


    private static final Map<Integer, JobType> codeTextMap = new HashMap<>();

    static {
        JobType[] values = JobType.values();
        for (JobType val : values) {
            codeTextMap.put(val.code, val);
        }
    }


    public static JobType getByCode(Integer code) {
        return codeTextMap.get(code);
    }

    public static String getTextByCode(Integer code) {
        JobType v = getByCode(code);

        if (null == v) {
            return "未知Code:" + code;
        }
        return v.text;
    }
}
